<?php

namespace app\store\model;

use app\common\model\OrderGoods as OrderGoodsModel;
use app\store\model\appointment\Type;

/**
 * 订单商品模型
 * Class OrderGoods
 * @package app\store\model
 */
class OrderGoods extends OrderGoodsModel
{


    /**
     * 获取预约类型
     * @return \think\Paginator
     */
    public function getOrderType($order_id = 0)
    {

        $model = Self::get(['order_id' => $order_id]);

        if ($model['goods_sku_id']) {
            $info = GoodsSku::get(['goods_sku_id' => $model['goods_sku_id']]);
            if ($info['type_id']) {
                return Type::get(['type_id' => $info['type_id'], 'is_delete' => 0]);
            } else {
                log_print('不存在type值');
                return false;
            }
        } else {
            log_print('不存在goods_sku_id值');
            return false;
        }

    }

    /*
     * 获取订单下商品
     */
    public function getOrderGoods($order_id)
    {
        $model = $this->where(['order_id' => $order_id])
            ->field('goods_sku_id,goods_name,goods_type,goods_sku_ids')->select();

        foreach ($model as $v) {
            if ($v['goods_type'] == 3) {
                $model = Db("goods_sku_copy")->where('goods_sku_id', 'in', explode(',', $v['goods_sku_ids']))
                    ->field('goods_sku_id,goods_sku_name goods_name')->select();
                break;
            }
        }
        return $model;


    }

}
